package com.lzc.test.controller;

import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.lzc.test.entity.request.HomeRequest;
import com.lzc.test.svc.serviceImpl.GetApplyTerminalImpl;

@Controller
public class Home {
	
	@Resource
	private GetApplyTerminalImpl getApplyTerminalImpl;
	
	private static final Logger logger = LoggerFactory.getLogger(Home.class);
	
	@RequestMapping(value = "/home")
	public ModelAndView home(@RequestBody HomeRequest request, ModelMap modelMap) {
		try {
			String applyId;
			if (request.getApplyId() != null) {
				applyId = request.getApplyId();
			} else {
				throw new RuntimeException("param is invalid");
			}
			
			@SuppressWarnings("unchecked")
			Map<String, Object> resultMap = getApplyTerminalImpl.getApplyTerminal(applyId);
			if (!ObjectUtils.nullSafeEquals(null, resultMap.get("applyTerminal"))) {
				logger.error("+++++++++++++++++++++++++++ SUCCESS +++++++++++++++++++++++++++++++++");
			} else {
				resultMap.put("applyTerminal", "No Info");
				resultMap.put("exception", "true");
				logger.error("++++++++++++++++++++++++++++ ERROR ++++++++++++++++++++++++++++++++++");
			}
			modelMap.put("data", resultMap);
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		
		return new ModelAndView("home");
	}

}
